package com.springbootblog.controller.fontend;

import com.springbootblog.service.fontend.ChatService;
import com.springbootblog.service.fontend.IndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 即时聊天部分接口
 * @className AboutController
 * @author camellia
 * @email 805795955@qq.com
 * @date 2024/01/01
 * @version 1.0
 */
@RequestMapping("java")
@RestController
//@CrossOrigin(origins="*",maxAge=3600)
public class ChatController
{
    /**
     * 定义一个静态常量日志对象
     */
    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    // 自动装载（service接口注入）
    @Autowired
    private ChatService chatService;

    @RequestMapping("/chat/getChatRecord")
    public Map<String,Object> getChatRecord(@RequestParam(defaultValue = "") String to_user_id, @RequestParam(defaultValue = "") String from_user_id, HttpServletRequest request) throws Exception
    {
        if(to_user_id.equals("") || from_user_id.equals("") )
        {
            Map<String,Object> result = new HashMap<>(2);
            result.put("code", -1);
            result.put("msg", "参数错误！");
            return result;
        }
        Map<String,Object> result = chatService.getChatRecord(to_user_id,from_user_id,request);
        return result;
    }
}
